﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace DataTools
{
    public class StoreProcedure
    {
        private List<SqlParameter> param = new List<SqlParameter>();
        private string name;

        /// <summary>
        /// Gets or sets the procedure name.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// Gets or sets the parameter list.
        /// </summary>
        public List<SqlParameter> Parameters
        {
            get { return param; }
        }

        /// <summary>
        /// Initializes the StoreProcedure with the given name.
        /// </summary>
        /// <param name="name">The StoreProcedure's name.</param>
        public StoreProcedure(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// Adds a parameter to the parameter collection of the StoreProcedure.
        /// </summary>
        /// <param name="paramName">The name of the parameter.</param>
        /// <param name="type">The SQL type.</param>
        /// <param name="size">The size.</param>
        /// <param name="value">The value.</param>
        public void AddParameter(string paramName, SqlDbType type, int size, object value)
        {
            try
            {
                param.Add(new SqlParameter(paramName, type, size));
                param[param.Count-1].Value = value;
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
